-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove Infrastructure Dependency on Web #54
Remove Infrastructure Dependency on Web #54
Conversation
…per class is all that's required.
…utoFac dependencies.
…ture dependency from Web.
…AutoFac. And return singleton so same database is used.
Build is failing, probably because it's running on linux not Windows and the build script is using the windows copy command?
|
@ardalis yeah looks like it. Digging into the build log I found:
And after Infrastructure builds we indeed call that post-build event:
It looks like the post-build step to manually copy the Infrastructure DLL to the output directory needs to be updated to a universal copy command of some kind. |
@ardalis we could also update the build to run against |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder that its appropriate way of thinking about removing infrastructure reference.
We can have two different approaches to building an app with this architecture.
First, self-hosted REST API + self-hosted SPA, that definitely remove reference to the infrastructure and keep all necessary references in place without hacks.
Second, both in bulk as now, but what about the situation when you will add some logic to infrastructure that belongs to configuration or helpers(with 3rd part references) and you need to use them in Web API?
I have this problem because I've created helpers for a data shaping mechanism, HATEOAS that lives inside infrastructure due to 3rd part references and used in both, infrastructure and web.
You can create an adapter to your own facade that hides implementation under core's service interfaces, but this overhead to helpers is appropriate?
As we know, developers are lazy and creating an abstraction over common mechanisms like extensions will be too much for some people.
I don't really see that web should have any additional logic despite display a result or create endpoints because we will just copy and paste this same 3rd part references and it can create friction because it's used in two places(infrastructure and web).
On the other hand, it completely hides all logic under services or repositories, you cannot force to break that and I agree that is the best way of thinking but with some boilerplate code.
# Conflicts: # src/CleanArchitecture.Web/Startup.cs
src/CleanArchitecture.Web/Startup.cs
Outdated
options.UseSqlite("Data Source=database.sqlite")); // will be created in web project root | ||
// options.UseInMemoryDatabase(dbName)); | ||
//options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); | ||
// TODO: Not sure where to call this database init now that we don't have access to AppDbContext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What to do for lack of access to the AppDbContext
type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use reflection to grab the infra assembly and instantiate it from there?
…there's access to AppDbContext. Add ref to Abstractions Microsoft NuGet package in Core. Add Ardalis EFCore package to Web, so it's available at runtime where it's needed.
@sdepouw Can we get this updated or abandon it? |
@sdepouw Any update on this? Trying to clean up old PRs. |
In a recent project I did a much more simplistic load of an Infrastructure assembly to remove the Web project reference to it. (Since connection strings are static per instance of my app, I pushed them from Web's Configuration into a static property of a class in Infrastructure, using an Interface from Shared. With that static variable set, Infrastructure can use it to keep awareness/management of db connections completely contained to itself.) From that experience, one issue here may be that Reflection's |
Closing this as it's pretty stale. Maybe I'll write a blog post with a smaller repo to demo how to do this. |
CleanArchitecture.Web
no longer has a dependency onCleanArchitecture.Infrastructure
Startup.cs
, by loading the physical fileAssembly.Load()
does not appear to work, since the Web project does not directly reference itRegisterAssemblyTypes
AppDbContext
is registered viaDatabaseModule
, which is referenced inStartup.cs
viabuilder.RegisterAssemblyModules
.